package com.sx.micowell.module.login.agreement

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.ContainerActivity
import com.example.mvvm.base.action.TitleBarAction
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.LogUtils
import com.gyf.immersionbar.ImmersionBar
import com.example.mvvm.bar.TitleBar
import com.miloyu.modelnet.response.HelpInfoVO
import com.miloyu.modelnet.response.UserAgreementVO
import com.sx.micowell.R
import com.sx.micowell.databinding.ActAgreementBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.module.web.WebViewFragment

/**
 * @Author: YY
 * @Time: 2021/9/1
 * @Describe TODO
 */
@Route(path = RoutePath.USER_AGREEMENT)
class UserAgreementFragment: MyFragment<ActAgreementBinding, ContainerActivity>(), TitleBarAction {

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var userAgreement : UserAgreementVO? = null


    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.act_agreement)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
        binding.title.setOnTitleBarListener(this)
    }

    override fun initData() {
        loadRootFragment(userAgreement)
    }

    private fun loadRootFragment(data: UserAgreementVO?) {
        LogUtils.d("loadRootFragment ${data?.userAgreement}")
        fragmentManager?.beginTransaction()?.add(R.id.fl_container,
            WebViewFragment.newInstance("", data?.userAgreement)
        )?.commit()
    }

    override fun getTitleBar(): TitleBar? {
        return binding.title
    }

    override fun onLeftClick(v: View?) {
        mActivity.finish()
    }

}